﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Mvc;
using TEST_SCCM_MVC_01.Models;

namespace TEST_SCCM_MVC_01.Controllers
{
    public class DeploymentController : Controller
    {


        /// <summary>
        /// 
        /// </summary>
        /// <param name="OSID"></param>
        /// <param name="OSName"></param>
        /// <param name="RoomID"></param>
        /// <param name="RoomName"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult MyArray(string[] OSID, string[] OSName, string[] RoomID, string[] RoomName)
        {
            // Build Response Array
            List<OSRoomResponse> ResponseList = new List<OSRoomResponse>();
            
            for (int i = 0; i < OSName.Length; i++)
            {
                ResponseList.Add(new OSRoomResponse {
                    OSID = OSID[i],
                    OSName = OSName[i],
                    RoomID = RoomID[i],
                    RoomName = RoomName[i]
                });
            }

            return View(ResponseList);
        }

        [HttpPost]
        public ActionResult StartDeployment(string[] OSID, string[] OSName, string[] RoomID, string[] RoomName)
        {
            // Build Response Array
            List<OSRoomResponse> ResponseList = new List<OSRoomResponse>();

            for (int i = 0; i < OSName.Length; i++)
            {
                ResponseList.Add(new OSRoomResponse
                {
                    OSID = OSID[i],
                    OSName = OSName[i],
                    RoomID = RoomID[i],
                    RoomName = RoomName[i]
                });
            }

            // Get only datarows with an OSID and a RoomID
            ResponseList = ResponseList.Where(r => !String.IsNullOrEmpty(r.OSID) && !String.IsNullOrEmpty(r.RoomID)).ToList();

            return View("MyArray",ResponseList);
        }
        //
        // GET: /Deployment/

        public ActionResult Index()
        {
            CollectionRepository ColRepo = new CollectionRepository();

            return View(ColRepo.GetAllCollections());
        }


        //
        // GET: /Deployment/TargetRooms

        [ChildActionOnly]
        public ActionResult TargetRooms()
        {

            CollectionRepository ColRepo = new CollectionRepository();

            return PartialView("PV_TargetRooms", ColRepo.GetAllSubCollections(WebConfigurationManager.AppSettings["DeploymentRoomRoot"]));
        }


        //
        // GET: /Deployment/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Deployment/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Deployment/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Deployment/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Deployment/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Deployment/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Deployment/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
